const app = getApp()
Page({
  data: {
    domainName: app.domainName,
    users:[],
    shenfen:1,
    isapply:0,
    openszhi:'hide',
    isTop:0,
    openid: app.globalData.openid
  },
  onLoad() {
    var _this=this;
    var _cha= app.screenHeight - 1420;
    if(_cha > 0){
      _this.setData({isTop:_cha/2});
    }
    _this.setData({openid:app.globalData.openid});
    wx.request({
      url: app.domainName + 'web/?c=getme',
      method: 'POST',
      data: {openid:app.globalData.openid}, header: { 'content-type': 'application/x-www-form-urlencoded' },
      success: function (res) {
           console.log(res);
           _this.setData({users:res.data.u, shenfen:res.data.u.shenfen, isapply:res.data.u.isapply})
          if(res.data.mt != ''){
            wx.showModal({
              showCancel:false,
              title: res.data.mbt,
              content: res.data.mt,
              success (res) {
              }
            })
               
          }
      }});
  },
  goqiudui(){
    if(false == this.checkQiuShenFen()){
      return;
   }
   var _shenfen=this.data.shenfen;
   if(2 == _shenfen){
    wx.redirectTo({url: '/pages/qguan/index'})
    return;
   }
   if(1 == _shenfen){
    wx.redirectTo({url: '/pages/qguan/qiuyuan'})
    return;
   }
    
  },
  gowode(){
    wx.redirectTo({url: '/pages/zdui/index'})
  },
  doszhi(e){
     var _id=e.currentTarget.dataset.id;
     var _this=this;
     if('open' == _id){
       _this.setData({openszhi:''});
     }
     if('close' == _id){
      _this.setData({openszhi:'hide'});
    }
    if('jie' == _id){
      var _shenfeng=_this.data.shenfen;
      console.log(_shenfeng)
      if(1 == _shenfeng){
         var _title='离开战队';
         var _desc='您确定要离开本战队';
      }else{
        var _title='解散战队';
        var _desc='您确定要解散本战队';
      }
      wx.showModal({
        title: _title,
        content: _desc,
        success (res) {
          if (res.confirm) {
            console.log('确定')
            wx.request({
              url: app.domainName + 'web/?c=leave',
              method: 'POST',
              data: {openid:app.globalData.openid}, header: { 'content-type': 'application/x-www-form-urlencoded' },
              success: function (res) {
                wx.redirectTo({url: '/pages/welcome/index'})
              }});
          } else if (res.cancel) {
            _this.setData({openszhi:'hide'});
          }
        }
      })

    }
     console.log(_id)
  },
  checkQiuShenFen(){
    var _shenfen=this.data.shenfen;
    if(1 == _shenfen){
      var _isapply=this.data.isapply; 
      if(1 == _isapply){
        return true;
      }else{
        wx.showToast({
          title: '您还未通过球员审批',
          icon: 'none',
          duration: 1500
        })
        return false;
      }
    }
  },
  doClick(e){
     var _id=e.currentTarget.dataset.id;
     if('dnss' == _id){
     if(false == this.checkQiuShenFen()){
        return;
     }
      wx.redirectTo({url: '/pages/syulan/index'});
      return;
     }
     if('noopen' == _id){
        wx.showToast({
          title: '暂未开放',
          icon: 'none',
          duration: 1500
        })
     }
     console.log(_id)
  },
  gosaicheng(){
    wx.request({
      url: app.domainName + 'web/?c=isduizhang',
      method: 'POST',
      data: {openid:app.globalData.openid}, header: { 'content-type': 'application/x-www-form-urlencoded' },
      success: function (res) {
           console.log(res.data.s);
           if('y' == res.data.s){
            wx.redirectTo({url: '/pages/saisi/index'})
           }else{
            wx.showToast({
              title: '您还未正式加入此球队',
              icon: 'none',
              duration: 1500
            })
           }
          
      }});
  },
  popMsg(msg){
    wx.showToast({
      title: msg,
      icon: 'none',
      duration: 1500
    })
  }
 
})
